/**
 * 打印控制台
 * @param {*} args 
 */
function log(...args) {
  console.log.apply(console, args);
}

const buf = Buffer.from('This is a test !');
console.log(buf.length); //16

// length是初始哈时确定的
const buf2 = Buffer.allocUnsafe(10);
buf2[0] = 2;
log(buf2.length);

// 指定base64编码的字符串
console.log(buf.toString('base64'));

// fill
const buf3 = Buffer.allocUnsafe(6);
log(buf3);
// 使用0xff填充 填充的索引范围 1-5 , 5不包含
log(buf3.fill(0xff, 1, 5));

// 比较内容

const buf4 = Buffer.from('a');
const buf5 = Buffer.from('a');
const buf6 = Buffer.from('A');

log(buf4 == buf5); //f
log(buf4.equals(buf5)); //t
log(buf5.equals(buf6)); //f

// indexOf ... lastIndexOf
const buf7 = Buffer.from('hello');
log(buf7.indexOf('ll')); // 2
log(buf7.indexOf('node')); // -1
